﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace MyServiceApp
{
    public partial class Service1 : ServiceBase
    {

        public Service1()
        {
            InitializeComponent();
        }

        public void OnDebug()
        {
            OnStart(null);
        }

        protected override void OnStart(string[] args)
        {            
            //System.IO.File.Create(AppDomain.CurrentDomain.BaseDirectory + "OnStart.txt");
            /*
            // get today's date at 10:00 AM  
            DateTime tenAM = DateTime.Now;
            // if 10:00 AM has passed, get tomorrow at 10:00 AM  
            if (DateTime.Now > tenAM)
                tenAM = tenAM.AddMinutes(1);

            // calculate milliseconds until the next 10:00 AM.  
            int timeToFirstExecution = (int)tenAM.Subtract(DateTime.Now).TotalMilliseconds;

            // calculate the number of milliseconds in 24 hours.   
            int timeBetweenCalls = (int)new TimeSpan(0, 1, 0).TotalMilliseconds;

            // set the method to execute when the timer executes.   
            TimerCallback methodToExecute = ProcessFile;

            // start the timer.  The timer will execute "ProcessFile" when the number of seconds between now and   
            // the next 10:00 AM elapse.  After that, it will execute every 24 hours.   
            System.Threading.Timer timer = new System.Threading.Timer(methodToExecute, null, timeToFirstExecution, timeBetweenCalls);

            // Block the main thread forever.  The timer will continue to execute.   
            Thread.Sleep(Timeout.Infinite);
             * */
        }

        public void ProcessFile(object obj)
        {
            MessageBox.Show("hello World");
        }

        protected override void OnStop()
        {
            System.IO.File.Create(AppDomain.CurrentDomain.BaseDirectory + "OnStop.txt");
        }
    }
}
